
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>内核基础 · book for xbook2</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="jason hu">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../task/task.html" />
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://book-os.org" target="_blank" class="custom-link">bookos</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" >
            
                <span>
            
                    
                    xbook2文档中心
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1" >
            
                <span>
            
                    
                    简介
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    xbook2 简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.2" >
            
                <span>
            
                    
                    快速上手
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.2.1" data-path="../../tutorial/quick-start.html">
            
                <a href="../../tutorial/quick-start.html">
            
                    
                    Qemu x86
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.3" >
            
                <span>
            
                    
                    内核
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter active" data-level="1.1.3.1" data-path="base.html">
            
                <a href="base.html">
            
                    
                    内核基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.2" data-path="../task/task.html">
            
                <a href="../task/task.html">
            
                    
                    任务管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.3" data-path="../timer/timer.html">
            
                <a href="../timer/timer.html">
            
                    
                    时钟管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.4" data-path="../mm/mm.html">
            
                <a href="../mm/mm.html">
            
                    
                    内存管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.5" data-path="../device/device.html">
            
                <a href="../device/device.html">
            
                    
                    设备管理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.3.5.1" data-path="../device/ahci.html">
            
                <a href="../device/ahci.html">
            
                    
                    AHCI磁盘驱动分析
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.1.3.5.2" data-path="../device/keyboard.html">
            
                <a href="../device/keyboard.html">
            
                    
                    PS/2键盘驱动分析
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.4" >
            
                <span>
            
                    
                    用户
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.4.1" data-path="../user/user.html">
            
                <a href="../user/user.html">
            
                    
                    用户编程
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.1.5" >
            
                <span>
            
                    
                    other
            
                </span>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1.5.1" data-path="../../other/FAQS.html">
            
                <a href="../../other/FAQS.html">
            
                    
                    FAQS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >内核基础</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="&#x5185;&#x6838;&#x57FA;&#x7840;">&#x5185;&#x6838;&#x57FA;&#x7840;</h1>
<p>&#x672C;&#x7AE0;&#x4ECB;&#x7ECD;xbook2&#x7684;&#x5185;&#x6838;&#x57FA;&#x7840;&#xFF0C;&#x5305;&#x62EC;&#xFF1A;&#x5185;&#x6838;&#x7B80;&#x4ECB;&#x3001;&#x5185;&#x6838;&#x7684;&#x542F;&#x52A8;&#x6D41;&#x7A0B;&#x4EE5;&#x53CA;&#x914D;&#x7F6E;&#x90E8;&#x5206;&#xFF0C;&#x4E3A;&#x540E;&#x9762;&#x7684;&#x7AE0;&#x8282;&#x5960;&#x5B9A;&#x57FA;&#x7840;&#x3002;&#x770B;&#x5B8C;&#x540E;&#x80FD;&#x8BA9;&#x5F00;&#x53D1;&#x8005;&#x5BF9;&#x5185;&#x6838;&#x6709;&#x4E00;&#x4E2A;&#x5927;&#x4F53;&#x7684;&#x4E86;&#x89E3;&#xFF0C;&#x5BF9;&#x5B83;&#x4E0D;&#x518D;&#x964C;&#x751F;&#x3002;</p>
<h2 id="xbook2-&#x5185;&#x6838;&#x4ECB;&#x7ECD;">xbook2 &#x5185;&#x6838;&#x4ECB;&#x7ECD;</h2>
<p>xbook2 &#x5185;&#x6838;&#x662F;&#x7C7B;unix&#x98CE;&#x683C;&#x7684;&#x7CFB;&#x7EDF;&#x5185;&#x6838;&#xFF0C;&#x5F88;&#x591A;&#x5185;&#x5BB9;&#x53C2;&#x8003;&#x4E86;&#x5F00;&#x6E90;&#x7684;linux&#x5185;&#x6838;&#x7684;&#x8BBE;&#x8BA1;&#xFF0C;&#x4E8E;&#x6B64;&#x540C;&#x65F6;&#xFF0C;&#x4E5F;&#x53C2;&#x8003;&#x4E86;windowsNT&#x5185;&#x6838;&#x4EE5;&#x53CA;&#x5176;&#x5B83;&#x5185;&#x6838;&#x7684;&#x8BBE;&#x8BA1;&#x4E0E;&#x5B9E;&#x73B0;&#x3002;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#xFF0C;&#x4E2D;&#x65AD;&#x7BA1;&#x7406;&#x4E3B;&#x8981;&#x53C2;&#x8003;&#x4E86;linux&#xFF0C;IO&#x9A71;&#x52A8;&#x7BA1;&#x7406;&#x53C2;&#x8003;&#x4E86;windowsNT&#x5185;&#x6838;&#xFF0C;&#x5176;&#x5B83;&#x6A21;&#x5757;&#x5927;&#x591A;&#x6570;&#x662F;&#x6211;&#x4EEC;&#x81EA;&#x5DF1;&#x5F00;&#x53D1;&#x3002;</p>
<p>xbook2&#x5185;&#x6838;&#x7684;&#x5185;&#x5BB9;&#x5305;&#x62EC;&#xFF1A;x86&#x5904;&#x7406;&#x5668;&#x76F8;&#x5173;&#x4EE3;&#x7801;&#x3001;&#x7269;&#x7406;&#x5185;&#x5B58;&#x548C;&#x865A;&#x62DF;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x3001;&#x591A;&#x4EFB;&#x52A1;&#x7BA1;&#x7406;&#x3001;&#x9A71;&#x52A8;&#x6846;&#x67B6;&#x3001;&#x6587;&#x4EF6;&#x7CFB;&#x7EDF;&#x3001;&#x7F51;&#x7EDC;&#x7CFB;&#x7EDF;&#x3001;&#x56FE;&#x5F62;&#x9A71;&#x52A8;&#x7CFB;&#x7EDF;&#x3001;IPC&#x7CFB;&#x7EDF;&#x3001;&#x65F6;&#x95F4;&#x7BA1;&#x7406;&#x7CFB;&#x7EDF;&#x7B49;&#x3002;&#x5185;&#x6838;&#x6700;&#x5C0F;&#x9700;&#x8981;&#x7684;300MB&#x8FD0;&#x884C;&#x5185;&#x5B58;&#x652F;&#x6301;&#xFF0C;&#x800C;&#x5185;&#x6838;&#x672C;&#x8EAB;&#x53EA;&#x6709;&#x51E0;&#x767E;KB&#x3002;</p>
<h2 id="&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;">&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;</h2>
<p>&#x4EFB;&#x52A1;&#x662F;xbook2&#x5185;&#x6838;&#x4E2D;&#x6700;&#x5C0F;&#x7684;&#x8C03;&#x5EA6;&#x5355;&#x4F4D;&#xFF0C;&#x4EFB;&#x52A1;&#x8C03;&#x5EA6;&#x7B97;&#x6CD5;&#x662F;&#x57FA;&#x4E8E;&#x4F18;&#x5148;&#x7EA7;&#x548C;&#x65F6;&#x95F4;&#x7247;&#x7684;&#x8C03;&#x5EA6;&#x7B97;&#x6CD5;&#x3002;&#x652F;&#x6301;4&#x4E2A;&#x4F18;&#x5148;&#x7EA7;&#xFF0C;&#x5206;&#x522B;&#x662F;LOW,NORMAL,HIGH,REALTIME&#x8FD9;4&#x4E2A;&#x4F18;&#x5148;&#x7EA7;&#xFF0C;LOW&#x662F;&#x6700;&#x4F4E;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#xFF0C;idle&#x4EFB;&#x52A1;&#x5C31;&#x662F;&#x5728;&#x8FD9;&#x4E2A;&#x4F18;&#x5148;&#x7EA7;&#x4E2D;&#xFF0C;NORMAL&#x662F;&#x7528;&#x6237;&#x4EFB;&#x52A1;&#x8FD0;&#x884C;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#xFF0C;HIGH&#x662F;&#x5BF9;&#x4E00;&#x4E9B;&#x8981;&#x6C42;&#x66F4;&#x9AD8;&#x7684;&#x4EFB;&#x52A1;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#xFF0C;REALTIME&#x662F;&#x963B;&#x585E;&#x5F0F;&#x9A71;&#x52A8;&#x4EFB;&#x52A1;&#x4F7F;&#x7528;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x3002;&#x76F8;&#x540C;&#x7684;&#x4F18;&#x5148;&#x7EA7;&#x7684;&#x4EFB;&#x52A1;&#x662F;&#x57FA;&#x4E8E;&#x65F6;&#x95F4;&#x7247;&#x8F6E;&#x8F6C;&#x8FDB;&#x884C;&#x8C03;&#x5EA6;&#x7684;&#xFF0C;&#x8C03;&#x5EA6;&#x5668;&#x603B;&#x662F;&#x83B7;&#x53D6;&#x4F18;&#x5148;&#x7EA7;&#x6700;&#x9AD8;&#x7684;&#x4EFB;&#x52A1;&#x6765;&#x8FDB;&#x884C;&#x8C03;&#x5EA6;&#x3002;</p>
<p>&#x4EFB;&#x52A1;&#x7BA1;&#x7406;&#x5C06;&#x5728;<a href="../task/task.html">&#x300A;&#x4EFB;&#x52A1;&#x7BA1;&#x7406;&#x300B;</a>&#x7AE0;&#x8282;&#x8BE6;&#x7EC6;&#x4ECB;&#x7ECD;&#x3002;</p>
<h2 id="&#x65F6;&#x949F;&#x7BA1;&#x7406;">&#x65F6;&#x949F;&#x7BA1;&#x7406;</h2>
<p>xbook2 &#x7684;&#x65F6;&#x949F;&#x7BA1;&#x7406;&#x662F;&#x4EE5;ticks&#x65F6;&#x949F;&#x8282;&#x62CD;&#x4E3A;&#x57FA;&#x7840;&#xFF0C;&#x65F6;&#x949F;&#x8282;&#x62CD;&#x662F;xbook2&#x4E2D;&#x6700;&#x5C0F;&#x7684;&#x65F6;&#x949F;&#x5355;&#x4F4D;&#x3002;xbook2&#x7684;&#x5B9A;&#x65F6;&#x5668;&#x662F;&#x5355;&#x6B21;&#x89E6;&#x53D1;&#x7684;&#xFF0C;&#x5C31;&#x662F;&#x5B9A;&#x65F6;&#x5668;&#x8D85;&#x65F6;&#x540E;&#x7CFB;&#x7EDF;&#x4F1A;&#x81EA;&#x52A8;&#x5C06;&#x5176;&#x5220;&#x9664;&#xFF0C;&#x5982;&#x679C;&#x8FD8;&#x60F3;&#x8981;&#x518D;&#x6B21;&#x4EA7;&#x751F;&#x8D85;&#x65F6;&#xFF0C;&#x5219;&#x9700;&#x8981;&#x91CD;&#x65B0;&#x8BBE;&#x7F6E;&#x8D85;&#x65F6;&#x65F6;&#x95F4;&#x3002;</p>
<p>&#x901A;&#x5E38;&#x4F7F;&#x7528;&#x5B9A;&#x65F6;&#x5668;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#xFF08;&#x5373;&#x8D85;&#x65F6;&#x51FD;&#x6570;&#xFF09;&#xFF0C;&#x5B8C;&#x6210;&#x5B9A;&#x65F6;&#x5668;&#x670D;&#x52A1;&#x3002;</p>
<p>&#x5B9A;&#x65F6;&#x5668;&#x5C06;&#x5728;<a href="../timer/timer.html">&#x300A;&#x65F6;&#x95F4;&#x7BA1;&#x7406;&#x300B;</a>&#x7AE0;&#x8282;&#x5C55;&#x5F00;&#x8BB2;&#x89E3;&#x3002;</p>
<h2 id="&#x5185;&#x5B58;&#x7BA1;&#x7406;">&#x5185;&#x5B58;&#x7BA1;&#x7406;</h2>
<p>xbook2 &#x5185;&#x5B58;&#x7BA1;&#x7406;&#x57FA;&#x4E8E;memnode&#x7269;&#x7406;&#x5185;&#x5B58;&#x6C60;&#x3001;memchache&#x865A;&#x62DF;&#x5185;&#x5B58;&#x548C;memspace&#x5185;&#x5B58;&#x7A7A;&#x95F4;&#x6765;&#x6784;&#x5EFA;&#x3002;&#x4ECE;&#x5185;&#x6838;&#x5185;&#x5B58;&#x5230;&#x8FDB;&#x7A0B;&#x5185;&#x5B58;&#x5B9E;&#x73B0;&#x4E86;&#x4E00;&#x5957;&#x6709;&#x5173;&#x8054;&#x7684;&#x7BA1;&#x7406;&#x6A21;&#x5F0F;&#x3002;&#x9664;&#x6B64;&#x4E4B;&#x5916;&#xFF0C;&#x91C7;&#x7528;&#x4E86;&#x5206;&#x9875;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#xFF0C;&#x53EF;&#x4EE5;&#x5B9E;&#x73B0;&#x8FDB;&#x7A0B;&#x7A7A;&#x95F4;&#x9694;&#x79BB;&#x6548;&#x679C;&#xFF0C;&#x4ECE;&#x800C;&#x8FBE;&#x5230;&#x8FDB;&#x7A0B;&#x548C;&#x5185;&#x6838;&#x4E92;&#x4E0D;&#x5E72;&#x6270;&#x3002;</p>
<p>&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x5C06;&#x5728;<a href="../mm/mm.html">&#x300A;&#x5185;&#x5B58;&#x7BA1;&#x7406;&#x300B;</a>&#x7AE0;&#x8282;&#x5C55;&#x5F00;&#x8BB2;&#x89E3;&#x3002;</p>
<h2 id="io&#x8BBE;&#x5907;&#x7BA1;&#x7406;">I/O&#x8BBE;&#x5907;&#x7BA1;&#x7406;</h2>
<p>xbook2 &#x9A71;&#x52A8;&#x6846;&#x67B6;&#x91C7;&#x53D6;&#x4E86;windowsNT&#x5F0F;&#x7684;&#x9A71;&#x52A8;&#x6846;&#x67B6;&#xFF0C;&#x5176;&#x76EE;&#x7684;&#x5728;&#x4E8E;&#x8BA9;&#x4EBA;&#x4E86;&#x89E3;&#x5230;&#x4E0D;&#x540C;&#x7684;&#x9A71;&#x52A8;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x3002;&#x5728;&#x8FD9;&#x4E2A;&#x6846;&#x67B6;&#x4E0B;&#x9762;&#xFF0C;&#x5206;&#x6210;&#x4E86;driver&#x5BF9;&#x8C61;&#x548C;device&#x5BF9;&#x8C61;&#xFF0C;&#x4E00;&#x4E2A;driver&#x5BF9;&#x8C61;&#x5BF9;&#x5E94;&#x7740;&#x591A;&#x4E2A;device&#x5BF9;&#x8C61;&#x3002;&#x540C;&#x65F6;&#x4E5F;&#x652F;&#x6301;open&#x3001;close&#x3001;read&#x3001;write&#x3001;ioctl&#x63A5;&#x53E3;&#x6846;&#x67B6;&#x3002;</p>
<p>I/O&#x8BBE;&#x5907;&#x7BA1;&#x7406;&#x5C06;&#x5728;<a href="../device/device.html">&#x300A;&#x8BBE;&#x5907;&#x6A21;&#x578B;&#x300B;</a>&#x7AE0;&#x8282;&#x5C55;&#x5F00;&#x8BB2;&#x89E3;&#x3002;</p>
<h2 id="xbook2-&#x542F;&#x52A8;&#x6D41;&#x7A0B;">xbook2 &#x542F;&#x52A8;&#x6D41;&#x7A0B;</h2>
<p>xbook2 &#x542F;&#x52A8;&#x65F6;&#xFF0C;&#x9700;&#x8981;&#x6709;&#x5F15;&#x5BFC;&#x7A0B;&#x5E8F;&#x6765;&#x505A;&#x6700;&#x57FA;&#x7840;&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x7136;&#x540E;&#x518D;&#x8DF3;&#x8F6C;&#x5230;&#x5185;&#x6838;&#x4E2D;&#x6267;&#x884C;&#x3002;</p>
<p>&#x76EE;&#x524D;&#x6211;&#x4EEC;&#x652F;&#x6301;&#x7684;&#x5F15;&#x5BFC;&#x6709;2&#x79CD;&#xFF0C;&#x4E00;&#x79CD;&#x662F;&#x6211;&#x4EEC;&#x81EA;&#x5DF1;&#x5199;&#x7684;&#x5F15;&#x5BFC;&#xFF0C;&#x57FA;&#x4E8E;&#x8F6F;&#x76D8;&#x6765;&#x7684;&#xFF0C;&#x7B80;&#x5355;&#x5FEB;&#x901F;&#x3002;&#x4E00;&#x79CD;&#x662F;&#x57FA;&#x4E8E;grub&#xFF08;multiboot2&#xFF09;&#x7684;&#x5F15;&#x5BFC;&#xFF0C;&#x6BD4;&#x8F83;&#x5F3A;&#x5927;&#x3002;x86&#x5904;&#x7406;&#x5668;&#x5148;&#x662F;&#x8FDB;&#x5165;16&#x4F4D;&#x6A21;&#x5F0F;&#x6267;&#x884C;&#xFF0C;&#x9700;&#x8981;&#x901A;&#x8FC7;&#x4EE3;&#x7801;&#x6267;&#x884C;&#x540E;&#xFF0C;&#x8FDB;&#x5165;32&#x4F4D;&#x6A21;&#x5F0F;&#xFF0C;&#x4E24;&#x79CD;&#x5F15;&#x5BFC;&#x65B9;&#x5F0F;&#x90FD;&#x5B9E;&#x73B0;&#x4E86;&#x76F8;&#x540C;&#x7684;&#x529F;&#x80FD;&#xFF0C;&#x5F15;&#x5BFC;&#x4F1A;&#x628A;&#x5185;&#x6838;&#x7A0B;&#x5E8F;&#x52A0;&#x8F7D;&#x5230;&#x5185;&#x5B58;&#x4E2D;&#xFF0C;&#x5E76;&#x5728;&#x6700;&#x540E;&#x8DF3;&#x8F6C;&#x5982;&#x5185;&#x6838;&#x6267;&#x884C;&#x3002;&#x4F60;&#x53EF;&#x4EE5;&#x5728;<code>xbook2/Makefile</code>&#x4E2D;&#x4FEE;&#x6539;<code>BOOT_MODE</code>&#x53D8;&#x91CF;&#x6765;&#x5207;&#x6362;&#x5F15;&#x5BFC;&#x65B9;&#x5F0F;&#x3002;</p>
<p><img src="figures/boot.png" alt="boot"></p>
<p>&#x5185;&#x6838;&#x7684;&#x5165;&#x53E3;&#x7A0B;&#x5E8F;&#x5728;<code>xbook2/src/arch/x86/mach-i386/entry.asm</code>&#x4E2D;&#x3002;&#x5185;&#x6838;&#x7684;&#x5165;&#x53E3;&#x7A0B;&#x5E8F;&#x5728;kernel_start&#x8FD9;&#x4E2A;&#x6807;&#x7B7E;&#x5904;&#xFF0C;&#x8FD9;&#x4E2A;&#x5730;&#x65B9;&#x662F;&#x5185;&#x6838;&#x6700;&#x5F00;&#x59CB;&#x6267;&#x884C;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x5982;&#x679C;&#x662F;grub&#x5F15;&#x5BFC;&#xFF0C;&#x5C31;&#x8FD8;&#x9700;&#x8981;&#x5728;&#x5176;&#x5B83;&#x5730;&#x65B9;&#x505A;&#x4E00;&#x5B9A;&#x7684;&#x5904;&#x7406;&#x540E;&#x518D;&#x8DF3;&#x8F6C;&#x8FC7;&#x6765;&#x3002;</p>
<p><img src="figures/mach-i386.png" alt="mach-i386"></p>
<p><img src="figures/x86-entry.png" alt="entry"></p>
<p>&#x7136;&#x540E;&#x4F1A;&#x8C03;&#x7528;<code>arch_init</code>&#x6765;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x548C;&#x5904;&#x7406;&#x5668;&#x76F8;&#x5173;&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x7136;&#x540E;&#x8DF3;&#x8F6C;&#x5230;<code>kernel_main</code>&#x4E2D;&#x6267;&#x884C;&#x4E00;&#x4E9B;&#x5E73;&#x53F0;&#x65E0;&#x5173;&#x7684;&#x7A0B;&#x5E8F;&#x3002;</p>
<p><img src="figures/x86-entry2.png" alt="x86-entry2.png"></p>
<p>arch&#x76F8;&#x5173;&#x7684;&#x521D;&#x59CB;&#x5316;&#x4F4D;&#x4E8E;<code>xbook2/src/arch/x86/mach-i386/arch.c</code>&#x4E2D;&#x3002;&#x5728;&#x91CC;&#x9762;&#x8FDB;&#x884C;&#x4E00;&#x4E9B;&#x5E73;&#x53F0;&#x76F8;&#x5173;&#x7684;&#x521D;&#x59CB;&#x5316;&#x3002;</p>
<p><img src="figures/x86-arch.png" alt="x86-arch"></p>
<p>&#x5F53;&#x5B8C;&#x6210;&#x4E86;arch&#x7684;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5C31;&#x4F1A;&#x8DF3;&#x8F6C;&#x5230;<code>kernel_main</code>&#x4E2D;&#x6267;&#x884C;&#x3002;&#x4F4D;&#x4E8E;<code>xbook2/src/init/main.c</code>&#x4E2D;&#x3002;</p>
<p><img src="figures/main.png" alt="main.c"></p>
<p>&#x5B8C;&#x6210;&#x6240;&#x6709;&#x521D;&#x59CB;&#x5316;&#x540E;&#xFF0C;&#x4F1A;&#x901A;&#x8FC7;<code>task_start_user</code>&#x53BB;&#x6267;&#x884C;&#x7B2C;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#x3002;&#x8BE5;&#x7A0B;&#x5E8F;&#x4F4D;&#x4E8E;<code>xbook2/src/task/task.c</code>&#x4E2D;</p>
<p><img src="figures/start_user.png" alt="start_user"></p>
<p>&#x5728;&#x8FD9;&#x91CC;&#x9762;&#xFF0C;&#x4F1A;&#x5148;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x8FDB;&#x7A0B;&#xFF0C;&#x8BA9;&#x8BE5;&#x8FDB;&#x7A0B;&#x53BB;&#x6267;&#x884C;<code>/sbin/init</code>&#x8FD9;&#x4E2A;&#x7A0B;&#x5E8F;&#xFF0C;&#x7136;&#x540E;&#x8FDB;&#x884C;schedule&#x8C03;&#x5EA6;&#xFF0C;&#x5C31;&#x4F1A;&#x8C03;&#x5EA6;&#x5230;&#x5176;&#x5B83;&#x4EFB;&#x52A1;&#x6267;&#x884C;&#x4E86;&#x3002;</p>
<p>&#x81F3;&#x6B64;&#xFF0C;&#x5185;&#x6838;&#x5C31;&#x5B8C;&#x6210;&#x4E86;&#x521D;&#x59CB;&#x5316;&#xFF0C;&#x5E76;&#x4E14;&#x542F;&#x52A8;&#x4E86;&#x7528;&#x6237;&#x7A0B;&#x5E8F;&#x3002;<code>/sbin/init</code>&#x7A0B;&#x5E8F;&#x4F1A;&#x542F;&#x52A8;&#x4E00;&#x4E2A;shell&#xFF0C;&#x7136;&#x540E;&#x6211;&#x4EEC;&#x5C31;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;&#x8FD9;&#x4E2A;shell&#x548C;&#x5185;&#x6838;&#x8FDB;&#x884C;&#x4EA4;&#x4E92;&#x4E86;&#x3002;</p>
<p><img src="figures/screenshoot.png" alt="qemu-run"></p>
<h2 id="xbook2-&#x5185;&#x6838;&#x914D;&#x7F6E;&#x793A;&#x4F8B;">xbook2 &#x5185;&#x6838;&#x914D;&#x7F6E;&#x793A;&#x4F8B;</h2>
<p>&#x5185;&#x6838;&#x5934;&#x6587;&#x4EF6;&#x914D;&#x7F6E;&#xFF1A;<code>xbook2/src/include/xbook/config.h</code></p>
<pre><code class="lang-c"><span class="hljs-comment">/* &#x914D;&#x7F6E;&#x5904;&#x7406;&#x5668;&#x4F4D;&#x5BBD; */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> CONFIG_32BIT</span>
<span class="hljs-comment">/* config large alloc size in memcache */</span>
<span class="hljs-meta">#<span class="hljs-meta-keyword">define</span> CONFIG_LARGE_ALLOCS</span>
</code></pre>
<p>Makefile&#x914D;&#x7F6E;&#xFF1A;<code>xbook2/Makefile</code></p>
<pre><code># set default boot mode (BOOT_GRUB2_MODE / BOOT_LEGACY_MODE)
export BOOT_MODE ?= $(BOOT_GRUB2_MODE)

# is qemu fat fs? (y/n)
QEMU_FAT_FS ?= n

# has net module? (y/n)
KERN_MODULE_NET    ?= n

# is livecd mode? (y/n)
KERN_LIVECD_MODE ?= n
</code></pre><p>myboot&#x56FE;&#x5F62;&#x6A21;&#x5F0F;&#x914D;&#x7F6E;&#xFF1A;<code>xbook2/src/arch/x86/boot/myboot/loader.asm</code></p>
<pre><code>; &#x542F;&#x52A8;&#x56FE;&#x5F62;&#x6A21;&#x5F0F;
%define CONFIG_GRAPHIC_ENABLE
</code></pre><p>grub&#x56FE;&#x5F62;&#x6A21;&#x5F0F;&#x914D;&#x7F6E;&#xFF1A;<code>xbook2/src/arch/x86/boot/multiboot2/multiboot2.S</code></p>
<pre><code># &#x542F;&#x52A8;&#x56FE;&#x5F62;&#x6A21;&#x5F0F;
#define CONFIG_GRAPHIC_ENABLE
</code></pre><footer class="page-footer"><span class="copyright">Copyright &#xA9; BookOS-developers 2021 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2021-06-16
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                
                <a href="../task/task.html" class="navigation navigation-next navigation-unique" aria-label="Next page: 任务管理">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"内核基础","level":"1.1.3.1","depth":3,"next":{"title":"任务管理","level":"1.1.3.2","depth":3,"path":"programing-manual/task/task.md","ref":"programing-manual/task/task.md","articles":[]},"previous":{"title":"内核","level":"1.1.3","depth":2,"ref":"","articles":[{"title":"内核基础","level":"1.1.3.1","depth":3,"path":"programing-manual/base/base.md","ref":"programing-manual/base/base.md","articles":[]},{"title":"任务管理","level":"1.1.3.2","depth":3,"path":"programing-manual/task/task.md","ref":"programing-manual/task/task.md","articles":[]},{"title":"时钟管理","level":"1.1.3.3","depth":3,"path":"programing-manual/timer/timer.md","ref":"programing-manual/timer/timer.md","articles":[]},{"title":"内存管理","level":"1.1.3.4","depth":3,"path":"programing-manual/mm/mm.md","ref":"programing-manual/mm/mm.md","articles":[]},{"title":"设备管理","level":"1.1.3.5","depth":3,"path":"programing-manual/device/device.md","ref":"programing-manual/device/device.md","articles":[{"title":"AHCI磁盘驱动分析","level":"1.1.3.5.1","depth":4,"path":"programing-manual/device/ahci.md","ref":"programing-manual/device/ahci.md","articles":[]},{"title":"PS/2键盘驱动分析","level":"1.1.3.5.2","depth":4,"path":"programing-manual/device/keyboard.md","ref":"programing-manual/device/keyboard.md","articles":[]}]}]},"dir":"ltr"},"config":{"plugins":["tbfed-pagefooter","livereload"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy BookOS-developers 2021","modify_label":"修订时间：","modify_format":"YYYY-MM-DD"},"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"jason hu","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"book for xbook2","language":"zh-hans","links":{"sidebar":{"bookos":"https://book-os.org"}},"gitbook":"3.2.3","description":"document for xbook2 kernel"},"file":{"path":"programing-manual/base/base.md","mtime":"2021-06-16T14:03:55.636Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2021-06-16T14:18:02.822Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

